package com.example.blogsystem.model;

import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String errorMsg;
    private T data;
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.setCode(StatusCode.RESULT_SUCCESS.getCode());
        result.setData(data);
        result.setErrorMsg("");
        return result;
    }

    public static <T> Result<T> fail(String errorMsg) {
        Result<T> result = new Result<T>();
        result.setErrorMsg(errorMsg);
        result.setCode(StatusCode.RESULT_FAIL.getCode());
        return result;
    }

    public static <T> Result<T> fail(String errorMsg,T data) {
        Result<T> result = new Result<T>();
        result.setErrorMsg(errorMsg);
        result.setCode(StatusCode.RESULT_FAIL.getCode());
        result.setData(data);
        return result;
    }
}
